<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Function combine</title>
<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../../index.html" title="Chapter 1. Range 2.0">
<link rel="up" href="../utilities.html" title="Utilities">
<link rel="prev" href="sub_range.html" title="Class sub_range">
<link rel="next" href="join.html" title="Function join">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="sub_range.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../utilities.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="join.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="range.reference.utilities.combine"></a><a class="link" href="combine.html" title="Function combine">Function combine</a>
</h4></div></div></div>
<p>
          The <code class="computeroutput"><span class="identifier">combine</span></code> function is
          used to make one range from multiple ranges. The <code class="computeroutput"><span class="identifier">combine</span></code>
          function returns a <code class="computeroutput"><span class="identifier">combined_range</span></code>
          which is an <code class="computeroutput"><span class="identifier">iterator_range</span></code>
          of a <code class="computeroutput"><span class="identifier">zip_iterator</span></code> from
          the Boost.Iterator library.
        </p>
<h5>
<a name="range.reference.utilities.combine.h0"></a>
          <span class="phrase"><a name="range.reference.utilities.combine.synopsis"></a></span><a class="link" href="combine.html#range.reference.utilities.combine.synopsis">Synopsis</a>
        </h5>
<p>
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span>
<span class="special">{</span>
    <span class="keyword">namespace</span> <span class="identifier">range</span>
    <span class="special">{</span>

<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">IterTuple</span><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">combined_range</span>
    <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">iterator_range</span><span class="special">&lt;</span><span class="identifier">zip_iterator</span><span class="special">&lt;</span><span class="identifier">IterTuple</span><span class="special">&gt;</span> <span class="special">&gt;</span>
<span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
    <span class="identifier">combined_range</span><span class="special">(</span><span class="identifier">IterTuple</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">IterTuple</span> <span class="identifier">last</span><span class="special">);</span>
<span class="special">};</span>

<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span><span class="special">...</span> <span class="identifier">Ranges</span><span class="special">&gt;</span>
<span class="keyword">auto</span> <span class="identifier">combine</span><span class="special">(</span><span class="identifier">Ranges</span><span class="special">&amp;&amp;...</span> <span class="identifier">rngs</span><span class="special">)</span> <span class="special">-&gt;</span>
    <span class="identifier">combined_range</span><span class="special">&lt;</span><span class="keyword">decltype</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">make_tuple</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">begin</span><span class="special">(</span><span class="identifier">rngs</span><span class="special">)...))&gt;</span>

    <span class="special">}</span> <span class="comment">// namespace range</span>
<span class="special">}</span> <span class="comment">// namespace boost</span>
</pre>
<p>
        </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
              <span class="bold"><strong>Precondition:</strong></span> For each type <code class="computeroutput"><span class="identifier">r</span></code> in <code class="computeroutput"><span class="identifier">Ranges</span></code>,
              <code class="computeroutput"><span class="identifier">r</span></code> is a model of <a class="link" href="../../concepts/single_pass_range.html" title="Single Pass Range">Single Pass Range</a>
              or better.
            </li>
<li class="listitem">
              <span class="bold"><strong>Return Type:</strong></span> <code class="computeroutput"><span class="identifier">combined_range</span><span class="special">&lt;</span><span class="identifier">tuple</span><span class="special">&lt;</span><span class="keyword">typename</span>
              <span class="identifier">range_iterator</span><span class="special">&lt;</span><span class="identifier">Ranges</span><span class="special">&gt;::</span><span class="identifier">type</span><span class="special">...&gt;</span>
              <span class="special">&gt;</span></code>
            </li>
<li class="listitem">
              <span class="bold"><strong>Returned Range Category:</strong></span> The minimum
              of the range category of every range <code class="computeroutput"><span class="identifier">r</span></code>
              in <code class="computeroutput"><span class="identifier">Ranges</span></code>.
            </li>
</ul></div>
<h5>
<a name="range.reference.utilities.combine.h1"></a>
          <span class="phrase"><a name="range.reference.utilities.combine.example"></a></span><a class="link" href="combine.html#range.reference.utilities.combine.example">Example</a>
        </h5>
<p>
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">range</span><span class="special">/</span><span class="identifier">combine</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">foreach</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">vector</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">list</span><span class="special">&gt;</span>

<span class="keyword">int</span> <span class="identifier">main</span><span class="special">(</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">const</span> <span class="keyword">char</span><span class="special">*[])</span>
<span class="special">{</span>
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">v</span><span class="special">;</span>
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">list</span><span class="special">&lt;</span><span class="keyword">char</span><span class="special">&gt;</span> <span class="identifier">l</span><span class="special">;</span>
    <span class="keyword">for</span> <span class="special">(</span><span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special">&lt;</span> <span class="number">5</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
    <span class="special">{</span>
        <span class="identifier">v</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="identifier">i</span><span class="special">);</span>
        <span class="identifier">l</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="keyword">static_cast</span><span class="special">&lt;</span><span class="keyword">char</span><span class="special">&gt;(</span><span class="identifier">i</span><span class="special">)</span> <span class="special">+</span> <span class="char">'a'</span><span class="special">);</span>
    <span class="special">}</span>

    <span class="keyword">int</span> <span class="identifier">ti</span><span class="special">;</span>
    <span class="keyword">char</span> <span class="identifier">tc</span><span class="special">;</span>
    <span class="identifier">BOOST_FOREACH</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tie</span><span class="special">(</span><span class="identifier">ti</span><span class="special">,</span> <span class="identifier">tc</span><span class="special">),</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">combine</span><span class="special">(</span><span class="identifier">v</span><span class="special">,</span> <span class="identifier">l</span><span class="special">))</span>
    <span class="special">{</span>
        <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="char">'('</span> <span class="special">&lt;&lt;</span> <span class="identifier">ti</span> <span class="special">&lt;&lt;</span> <span class="char">','</span> <span class="special">&lt;&lt;</span> <span class="identifier">tc</span> <span class="special">&lt;&lt;</span> <span class="char">')'</span> <span class="special">&lt;&lt;</span> <span class="char">'\n'</span><span class="special">;</span>
    <span class="special">}</span>

    <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
<span class="special">}</span>
</pre>
<p>
        </p>
<p>
          This produces the output:
</p>
<pre class="programlisting"><span class="special">(</span><span class="number">0</span><span class="special">,</span><span class="identifier">a</span><span class="special">)</span>
<span class="special">(</span><span class="number">1</span><span class="special">,</span><span class="identifier">b</span><span class="special">)</span>
<span class="special">(</span><span class="number">2</span><span class="special">,</span><span class="identifier">c</span><span class="special">)</span>
<span class="special">(</span><span class="number">3</span><span class="special">,</span><span class="identifier">d</span><span class="special">)</span>
<span class="special">(</span><span class="number">4</span><span class="special">,</span><span class="identifier">e</span><span class="special">)</span>
</pre>
<p>
        </p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2003-2010 Thorsten Ottosen,
      Neil Groves<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="sub_range.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../utilities.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="join.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
